<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!-- 게시물 수정 권한에 대한 상세 로직 설정 필요.
	 게시물 수정 권한을 받았을시 수정할수있는 범위 설정도 상의 필요
 -->


<script type="text/javascript">

$(function(){
	 $.ajax({
			type:"post",
			url:"${initParam.root}auction/findByCategory.do",
			datatype:"json",
			success:function(data){		
				
				 var BigClassList="<option value=''>--카테고리--</option>"; 
					$.each(data, function(index, value){
						BigClassList+="<option value='"+value.bigClassNo+"'>"+value.bigClassName+"</option>";							
					});						
					$("#auctionRegisterView select[name=selBigClass]").html(BigClassList); 
			}//success
		});//ajax	 		
	
		 $("#auctionRegisterView select[name=selBigClass]").change(function(){		
		    	var bigClass = $("#auctionRegisterView select[name=selBigClass]").val();
					
		    		$.ajax({
							type:"post",
							url:"${initParam.root}auction/getSmallClassList.do",
							datatype:"json",
							data:"bigClass="+bigClass,
							success:function(data){						
								 	 var smallClassList="<option value=''>--카테고리--</option>"; 
								$.each(data, function(index, value){
									 smallClassList+="<option value='"+value.smallClassNo+"'>"+value.smallClassName+"</option>";							
								});						
								$("#auctionRegisterView select[name=selSmallClass]").html(smallClassList); 
							}//success
						});//ajax
			});//change
			
	$("#auctionRegisterView select[name=selSmallClass]").change(function(){
		var smallClassNo = $("#auctionRegisterView select[name=selSmallClass]").val();
		//alert("smallClassNo "+smallClassNo);
		$("#auctionRegisterView :input[name=smallClassNo]").val(smallClassNo);
	});//change
});//ready
</script>

 <script type="text/javascript">
 var p=$("#auctionPrice").val();
 var p2=$("#buyPrice").val();
 p=Number(p);
 p2=Number(p2);
 $(document).ready (function(){
	 $("#auctionRegisterView").submit(function(){
		 if(p<p2){
			 alert("즉시 구매 보다 경매가가 커야 합니다. ");
			 return false;
		 }
		 if($("#selBigClass").val()==""){
			  alert("카테고리 선택 ");
			  return false;
		 }else if($("#selSmallClass").val()==""){
			 alert("소분류 선택 ");
			  return false;
		 }else if($("#boardTitle").val()==""){
			 alert("제목 입력");
			  return false;
		 }  else if($("#boardTitle").val()==""){
					 alert("제목 입력");
					  return false;
		 }else if($("#boardContent").val()==""){
			 alert("내용 입력");
			  return false;
		 }else if($("#auctionPrice").val()==""){
			 alert("경매가 입력");			 
			  return false;
		 }else if($("#auctionTime").val()==""){
			 alert("시간 선택 ");
			  return false;
		 }else if($("#buyPrice").val()==""){
			 alert("즉시구매가 입력 ");
			  return false;
		 }else if($("#quantity").val()==""){
			 alert("수량 입력 ");
			  return false;
		 }else if(isNaN($("#auctionPrice").val())||isNaN($("#buyPrice").val())||isNaN($("#quantity").val())){
			 alert("숫자로 입력해주세요!");
			 return false;
		 }
	 });
 });
 </script>


<form id="auctionRegisterView" action="${initParam.root}auction/auth_auctionRegister.do" method="post" enctype="multipart/form-data" >
<input type="hidden" id="smallClassNo" name="smallClassNo">
<!-- memberNo는 세션에 저장되어있는 로그인된 회원의 No 세팅 -->
<input type="hidden" id="memberNo" name="memberNo" value="${sessionScope.mvo.memberNo }">


<table class="content">
<tr>
	<td>카테고리</td>
		<td>
			<select  id="selBigClass" name="selBigClass">
				<option value="">대분류</option>			
			</select>
			
			<select id="selSmallClass" name="selSmallClass">
				<option value="">소분류</option>				
			</select>
			<input type="hidden" id="smallClassNo" name="smallClassNo">
		</td>
</tr>
<tr>
		<td>게시물 제목</td> 
		<td><input type="text" name="boardTitle" id="boardTitle" ></td>
</tr>
<tr>
	<td>내용</td>
	<td><textarea rows="20" cols="50" name="boardContent" id="boardContent"></textarea></td>
</tr>
<tr>
	<td>경매가</td>
	<td><input type="text" id="auctionPrice" name="auctionPrice"></td>
</tr>
<tr>	
	<td>경매시간</td>
	<td>
		<select id="auctionTime" name="auctionTime">
			<option value="">시간선택</option>
			<option value="1">1일</option>
			<option value="3">3일</option>
			<option value="7">7일</option>
		</select>
	</td>
</tr>
<tr>
	<td>즉시구매가</td>
	<td><input type="text" id="buyPrice" name="buyPrice"></td>
</tr>
<tr>
	<td>수량</td>
	<td><input type="text" id="quantity" name="quantity"></td>
	
</tr>
<tr>
	<td>첨부파일</td>
	<td> <input type="file" name="uploadFile"><br></td>
	
</tr>
<tr>
	<td colspan="2"><input type="submit" value="등록" ></td>
</tr>

</table>
</form>